<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html style='height:100%;'>
<head>
<base href="<%=basePath%>">

<title>隐检新增</title>
<link rel="stylesheet" href="css/vivo.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="js/bootstrap2/css/bootstrap.min.css">
<link rel="stylesheet" href="css/common.css">
<link href="js/select2/select2.min.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" type="text/css"
	href="static/p_house/house_index.css" />
<link rel="stylesheet" type="text/css"
	href="js/webuploader-0.1.5/webuploader.css" /> 

<script src="js/jquery-1.11.1.js"></script>
<script src="js/bootstrap2/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script>
<script type="text/javascript"
	src="<%=basePath%>js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="js/webuploader-0.1.5/webuploader.js"></script>
<script type="text/javascript" src="js/sharefunction.js"></script>
<script src="js/select2/select2.min.js"></script>
<script type="text/javascript" src="js/form.js"></script>
<!-- 图片放大 -->
<script src="js/postbird-img-glass/postbird-img-glass.js"></script>
<style>
.webuploader-container {
	position: relative;
	top: 5px;
}
</style>
</head>
<body>
	<!-- 装修隐检 -->
	<form class="cmxform" id="decorationHideCheckAdd" method="post"
		action="decorate/hideCheck/add">
		<input type="hidden" id="hideCheckAdd_articleId">
		<div>
			<div class="panel panel-default">
				<div class="panel-body">
					<table cellpadding="10" cellspacing="5" class="mytable">
						<tr>
							<td width="70" class="td-right">隐检时间</td>
							<td><input name="hideTime" class="Wdate" readonly="readonly"
								onClick="WdatePicker({ dateFmt: 'yyyy-MM-dd'})" /></td>
							<td width="70" class="td-right">隐检项目</td>
							<td><input name="hideName" value="" /></td>
						</tr>
						<tr>
							<td width="70" class="td-right">隐检内容</td>
							<td><textarea rows="3" cols="70" style="width:70%"
									name="hideContent"></textarea></td>
							<td width="70" id="examine" class="td-right">隐检结论</td>
							<td><textarea rows="3" cols="70" style="width:70%"
									name="hideVerdict"></textarea></td>
						</tr>
						<tr>
							<td width="70" class="td-right">资料</td>
							<td colspan="3"><input name="hideData" value="" /> <!-- 附件上传 资料附件。。。-->
								<!-- 上传按钮 -->
								<div id='filePicker_yjzl' style="display:none;">上传</div>
								<!-- 缩略图容器 -->
								<div id='list_yjzl'></div></td>
						</tr>
					</table>
					<!-- 修改时添加变更说明 -->
					<div style="margin:10px;display:none;" id="dh_div" >
						变更说明<textarea rows="3" name="remark" id="dhRemark" style="width:70%"></textarea><span style="color:red;">*</span>
					</div>
				</div>
			</div>
			<div style="width:100%;text-align:center; padding-top:20px">
				<div id="btn_div1" style="display:none;">
					<button class="btn btn-danger radius my-btn"
						onclick="saveHideContent(0)" type="button">提交</button>
					<button class="btn btn-danger radius my-btn"
						onclick="saveHideContent(1)" type="button">保 存</button>
					<a class="btn btn-default radius" 
						onClick="resetForms('decorationHideCheckAdd');"> 重置 </a> <br />
				</div>
				<div id="btn_div2" style="display:none;">
					<!-- <button id="modifyBtn" type="button"
						class="btn btn-danger radius my-btn" onclick="saveHideContent(3)">启用编辑</button> -->
					<button class="btn btn-danger radius my-btn "
						onclick="saveHideContent(2)" type="button">保存修改</button>
					<button class="btn btn-default radius " type="button"
						onClick="resetForms('decorationHideCheckAdd');">重置</button>
				</div>
			</div>
		</div>
		<!-- 隐藏域 -->
		<div style="display:none;">
			<input name="hideId" id="entityId_hideId" value="${id }" />
		</div>

	</form>

	<script type="text/javascript">
		$(function() {
			getHideFiles();
			//初始化表单
			mySubmit("decorationHideCheckAdd", saveHideCheck, hideCheckAddSuccess);
			initWebUpload("filePicker_yjzl", "list_yjzl", "隐检资料附件", "hideCheckAdd_articleId", planStageSuccess, planStageErr);
			//上传按钮添加默认宽高
			$("div[id^='filePicker_'] div").css({
					"width" : "60px",
					"height" : "28px"
				});
			//上传按钮水平排列
			//$("div[id^='filePicker_']").css("display", "inline-block");
			//获取编辑页面数据
			initDecHideMsg();
			if(hideFlag=='2'){
				$("#dh_div").show();
			}
		});
		//展示附件
		function getHideFiles() {
			getFileList($("#decorationHideCheckAdd input[name='hideId']").val(), "隐检资料附件", "#list_yjzl",setHideRFL,imgHidePlus,imgHideBtnHide);
		}
		//图片放大
		function imgHidePlus(data) {
			$.each(data, function(i, v) {
				//图片放大
				PostbirdImgGlass.init({
					domSelector : "#" + v.id + " img",
					animation : true,
					height : '80%',
					myDocument : window.parent.parent.parent
				});
			});
		}
	var rFileList=new Array();//
		//设置待删除附件的值到集合中
	function setHideRFL(id,_this){
		layer.confirm('删除该图片？',{
			title:'警告',
			icon:0,
			shade:[0.1, '#fff']
		},function(){
			rFileList.push(id);
			//删除指定缩略图
			$("#"+id).remove();
			layer.close(layer.index);
		});
	}
	//图片上传成功后隐藏删除按钮
	function imgHideBtnHide(id){
		//隐藏图片删除按钮
		$("#"+id+" span").hide();
		//禁止点击上传按钮
		$("#decorateSchemeForm div[id^='filePicker']").unbind("click").click(function(){
			return false;
		}).hide();
	}
		//初始化赋值
		var hideFlag='${hideFlag}';//查看、编辑状态
		function initDecHideMsg() {
			var hideId = $("#decorationHideCheckAdd").find("#entityId_hideId").val();
			if (hideId == "") {
				//重置表单
				$("#decorationHideCheckAdd")[0].reset();
				$("#decorationHideCheckAdd #btn_div2").hide();
				$("#decorationHideCheckAdd #btn_div1").show();
				$("#decorationHideCheckAdd div[id^='filePicker_']").css({"display":"inline-block","vertical-align":"bottom"});
			} else {
				$.post("decorate/hideCheck/getHideById", {
					id : hideId
				}, function(data, status) {
					if (data != null) {
						$("#decorationHideCheckAdd input[name='hideTime']").val(new Date(data.hideTime).format('yyyy-MM-dd'));
						$("#decorationHideCheckAdd [name='hideVerdict']").val(data.hideVerdict);
						$("#decorationHideCheckAdd [name='hideContent']").val(data.hideContent);
						$("#decorationHideCheckAdd input[name='hideName']").val(data.hideName);
						$("#decorationHideCheckAdd input[name='hideData']").val(data.hideData);
						if(hideFlag == "1"){
							//隐藏按钮
							$("#decorationHideCheckAdd #btn_div2").hide();
							$("#decorationHideCheckAdd #btn_div1").hide();
							$("#decorationHideCheckAdd").find("input,textarea").attr("readonly", true);
							$("#decorationHideCheckAdd").find(".addbtn,select,input[type='file'],.Wdate").attr("disabled", true);
							//禁止点击上传按钮
							$("#decorationHideCheckAdd div[id^='filePicker_']").css("display", "none");
						
						}else{
							$("#decorationHideCheckAdd #btn_div2").show();
							$("#decorationHideCheckAdd #btn_div1").hide();
							$("#decorationHideCheckAdd .uploadcancel").show();
							$("#decorationHideCheckAdd div[id^='filePicker_']").css({"display":"inline-block","vertical-align":"bottom"});
						}
					}
				});
			}
		}
	
		var optHide;
		//optHide操作字段，0：临时保存；1：新增；2：修改
		function saveHideContent(val) {
			optHide = val;
			if (val == 3) {
				//解除锁定状态
				var index = layer.confirm('确定开启编辑状态？', {
					offset : '20%',
					shade : 0
				}, function() {
					//去除只读开启按钮编辑
					$("#decorationHideCheckAdd").find("input,textarea").attr("readonly", false);
					$("#decorationHideCheckAdd").find("select,.addbtn,input[type='file'],.Wdate").attr("disabled", false);
					$("#decorationHideCheckAdd").find(".Wdate").attr("readonly", true);
					$("#decorationHideCheckAdd #modifyBtn").hide();
					$("#decorationHideCheckAdd .hidbtn").addClass("showbtn");
					//禁止点击上传按钮
					$("#decorationHideCheckAdd div[id^='filePicker_']").css({"display":"inline-block","vertical-align":"bottom"});
					$("#decorationHideCheckAdd .uploadcancel").show();
					layer.close(index);
				});
			} else if(val == 2){
				var approvalCount = ${approvalCount};
				if(approvalCount == 0 ){
					//提交表单
					$("#decorationHideCheckAdd").submit();
				}else{
					layer.msg("此条数据已提交过审批，不能重复提交");
				}
			}else{
				$("#decorationHideCheckAdd").submit();
			}
		}
	
		//成功后调用方法
		function hideCheckAddSuccess(responseText) {
			layer.close(layer.index);
			if (responseText.success) {
				layer.alert("保存成功！", {
					offset:'20%',
					shade:0.1
				}, function() {
					parent.parent.tabToken=2;
					parent.location.reload();
				});
	
			} else {
				layer.msg('保存失败！');
			}
		}
	
		function saveHideCheck() {
			var i = layer.load(2);
			//房间号、客户id预留
			var fkcustomerId = window.parent.parent.$("#customerId").val();
			var fkroomId = window.parent.parent.$("#roomId").val();
			var hideTime = $("#decorationHideCheckAdd input[name='hideTime']").val();
			var hideName = $("#decorationHideCheckAdd input[name='hideName']").val();
			var hideData = $("#decorationHideCheckAdd input[name='hideData']").val();
			var hideContent = $("#decorationHideCheckAdd textarea[name='hideContent']").val();
			var hideVerdict = $("#decorationHideCheckAdd textarea[name='hideVerdict']").val();
			var hideCheckAccessoryCaList = $("#decorationHideCheckAdd #hideCheckAdd_articleId").val();
			var hideId = $("#decorationHideCheckAdd input[name='hideId']").val();
			var remark = $("#decorationHideCheckAdd #dhRemark").val();
			if(optHide == "2"){
				if(remark == "" || remark == undefined){
					layer.msg("变更说明不能为空");
					layer.close(i);
					return null;
				}
			}
			var date = new Date();
			var hiTime= new Date(hideTime);
			if(hiTime > date){
				 layer.close(i);
				 $("#decorationHideCheckAdd input[name='hideTime']").focus();
				 layer.msg("隐检时间不能大于当前时间");
				 return null;
			}
			return {
				id : hideId,
				fkcustomerId : fkcustomerId,
				fkroomId : fkroomId,
				hideTime : hideTime,
				hideName : hideName,
				hideContent : hideContent,
				hideData : hideData,
				hideVerdict : hideVerdict,
				hideCheckAccessoryCaList : hideCheckAccessoryCaList,
				opt : optHide,
				rFileList:rFileList,
				remark : remark
			}
		}
	
		//上传成功回调
		function planStageSuccess(file, response) {
			PostbirdImgGlass.init({
				domSelector : "td img",
				animation : true,
				height : '80%',
				myDocument : window.parent.parent.parent
			});
		}
		//上传失败回调
		function planStageErr(file, data) {
			//alert("上传失败回调");
		}
	</script>
</body>
</html>
